package com.liu.backstage.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liu.backstage.model.Role;
import com.liu.backstage.service.RoleService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 腾杰说
 * @since 2020-07-10
 */
@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/findAll")
    public String findAll( Model model){

        List<Role> list = roleService.list();
        model.addAttribute("roleList",list);
        return "role-list";
    }

    @RequestMapping("/roledelect")
    @ResponseBody
    public String roledelect(Integer id){
        roleService.removeById(id);
        return "true";
    }

    @RequestMapping("/role-add")
    public String roleAdd(){
        return "role-add";
    }
    @RequestMapping("/save")
    public String save(Role role){
       roleService.save(role);
       return "redirect:findAll";
    }

}

